import { addComp, delComp, findAllComp, findComp, updateComp } from '@renderer/apis/compAPI'
import { ref } from 'vue'

export default () => {
  const comps = ref<compModel[]>()
  const comp = ref<compModel>()

  const all = async (args = {}) => {
    const { data } = (await findAllComp(args)) as any
    comps.value = data
  }

  const find = async (id: number) => {
    const { data } = (await findComp(id)) as any
    comp.value = data
  }

  const add = async (data: any) => {
    return await addComp(data)
  }

  const update = async (id: number, data: any) => {
    await updateComp(id, data)
  }

  const del = async (id: number) => {
    await delComp(id)
  }

  return { add, all, del, find, update, comps, comp }
}
